package com.uroad.jilinpda.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.uroad.jilinpda.R;
import com.uroad.lib.util.sys.SystemUtil;


public class OBUConfirmDialog extends Dialog {
    private Activity context;
    private TextView tvOderNo;
    private TextView tvPlateNo;
    private TextView tvPlateColor;
    private Button btnCancel;
    private Button btnConfirm;
    private OnDilaogClickListener onDilaogClickListener;

    public OBUConfirmDialog(Context context) {
        super(context, R.style.default_dialog);
        this.context = (Activity) context;
        initView();
        initListener();
    }

    private void initView() {
        View view = View.inflate(context, R.layout.dialog_obu_confirm_alert, null);
        tvOderNo = (TextView) view.findViewById(R.id.tvOderNo);
        tvPlateNo = (TextView) view.findViewById(R.id.tvPlateNo);
        tvPlateColor = (TextView) view.findViewById(R.id.tvPlateColor);
        btnCancel = (Button) view.findViewById(R.id.btnCancel);
        btnConfirm = (Button) view.findViewById(R.id.btnConfirm);
        setContentView(view);
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams params = window.getAttributes();
            float width = SystemUtil.getScreenWidth((Activity) context);
            params.width = (int) (width - 100);
            params.gravity = Gravity.CENTER_HORIZONTAL;
            window.setAttributes(params);
        }
    }

    private void initListener() {
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onDilaogClickListener != null) {
                    onDilaogClickListener.onCancel();
                }
            }
        });
        btnConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onDilaogClickListener != null) {
                    onDilaogClickListener.onConfirm();
                }
            }
        });
    }

    public void setOnDilaogClickListener(OnDilaogClickListener onDilaogClickListener) {
        this.onDilaogClickListener = onDilaogClickListener;
    }

    public interface OnDilaogClickListener {
        void onCancel();
        void onConfirm();
    }

    public void setData(String orderNo, String plateNo, String plateColor) {
        tvOderNo.setText(orderNo);
        tvPlateNo.setText(plateNo);
        tvPlateColor.setText(plateColor);
    }
}
